package com.yycwxt.modules.front.test.controller;

import com.yycwxt.common.ReturnResult;
import com.yycwxt.domain.User;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("redis")
public class RedisTestController {

    private final RedisTemplate<Object, Object> redisTemplate;

    public RedisTestController(RedisTemplate redisTemplate) {
        this.redisTemplate = redisTemplate;
    }

    @GetMapping("save")
    public ReturnResult save(){
        User user = new User();
        user.setCode("11111");
        user.setPassword("11111");
        user.setUsername("lmy");
        redisTemplate.opsForValue().set("user", user);
        return ReturnResult.buildSuccessResult(redisTemplate.opsForValue().get("user"));
    }

}